```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ负载均衡机制详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            background-color: #f9fafb;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
            color: white;
        }
        .code-block {
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .nav-item:hover {
            color: #3b82f6;
            border-bottom: 2px solid #3b82f6;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .diagram-container {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">RocketMQ负载均衡机制</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入解析Producer端、Consumer端和Broker集群的负载均衡实现原理</p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#producer" class="px-6 py-3 bg-white text-blue-700 font-medium rounded-lg hover:bg-blue-50 transition-all">
                    <i class="fas fa-paper-plane mr-2"></i>Producer端
                </a>
                <a href="#consumer" class="px-6 py-3 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-all">
                    <i class="fas fa-users mr-2"></i>Consumer端
                </a>
                <a href="#broker" class="px-6 py-3 bg-white text-blue-700 font-medium rounded-lg hover:bg-blue-50 transition-all">
                    <i class="fas fa-server mr-2"></i>Broker集群
                </a>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="sticky top-0 bg-white shadow-sm z-10">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <div class="flex space-x-8">
                    <a href="#producer" class="nav-item inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700">Producer端</a>
                    <a href="#consumer" class="nav-item inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700">Consumer端</a>
                    <a href="#broker" class="nav-item inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700">Broker集群</a>
                    <a href="#best-practices" class="nav-item inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700">最佳实践</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Producer Section -->
        <section id="producer" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-paper-plane text-3xl text-blue-600 mr-4"></i>
                <h2 class="text-3xl font-bold">Producer端的负载均衡机制</h2>
            </div>
            <p class="text-lg text-gray-700 mb-8">RocketMQ的Producer端负载均衡是指将消息均匀地分发到多个队列（Queue）和多个Broker上，以充分利用集群资源，提高系统吞吐量和可用性。</p>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 text-blue-600 flex items-center">
                        <i class="fas fa-list-ol mr-2"></i> 队列选择机制
                    </h3>
                    <p class="mb-4">RocketMQ Producer在发送消息时，会根据一定的策略选择目标队列。</p>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span><strong>默认队列选择策略：</strong>轮询(Round-Robin)方式选择队列</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span><strong>延迟容错队列选择策略：</strong>避开最近发送失败或延迟较高的Broker</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span><strong>自定义队列选择器：</strong>允许用户实现特定业务需求的队列选择逻辑</span>
                        </li>
                    </ul>
                </div>

                <div class="code-block p-6 rounded-xl">
                    <pre><code class="language-java">// DefaultMQProducerImpl.java中的队列选择逻辑
private MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, 
                                         final String lastBrokerName) {
    if (this.sendLatencyFaultEnable) {
        try {
            // 启用延迟容错时的队列选择逻辑
            // ...
        } catch (Exception e) {
            // ...
        }
    }

    // 默认轮询选择队列
    return tpInfo.selectOneMessageQueue(lastBrokerName);
}</code></pre>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">1.1 默认队列选择策略</h3>
            <div class="code-block p-6 rounded-xl mb-8">
                <pre><code class="language-java">public MessageQueue selectOneMessageQueue(final String lastBrokerName) {
    // 如果上次发送失败，尽量选择其他Broker上的队列
    if (lastBrokerName != null) {
        // ...
    }
    
    // 轮询选择队列
    int index = this.sendWhichQueue.getAndIncrement();
    int pos = Math.abs(index) % this.messageQueueList.size();
    return this.messageQueueList.get(pos);
}</code></pre>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">特点：</h4>
                    <ul class="space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>简单高效，确保消息均匀分布到各个队列</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>不考虑队列所在Broker的负载情况</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>适用于大多数场景</span>
                        </li>
                    </ul>
                </div>
                <div class="diagram-container">
                    <div class="mermaid">
                        pie
                            title 默认队列选择策略
                            "Broker1队列1" : 25
                            "Broker1队列2" : 25
                            "Broker2队列1" : 25
                            "Broker2队列2" : 25
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">1.2 延迟容错队列选择策略</h3>
            <div class="code-block p-6 rounded-xl mb-8">
                <pre><code class="language-java">public MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, 
                                         final String lastBrokerName) {
    if (this.sendLatencyFaultEnable) {
        try {
            // 尝试选择一个可用的、延迟较低的队列
            int index = tpInfo.getSendWhichQueue().getAndIncrement();
            for (int i = 0; i < tpInfo.getMessageQueueList().size(); i++) {
                int pos = Math.abs(index++) % tpInfo.getMessageQueueList().size();
                MessageQueue mq = tpInfo.getMessageQueueList().get(pos);
                // 检查该Broker是否可用（未故障或已恢复）
                if (latencyFaultTolerance.isAvailable(mq.getBrokerName())) {
                    return mq;
                }
            }
            
            // 如果所有Broker都不可用，选择一个恢复最快的
            final String notBestBroker = latencyFaultTolerance.pickOneAtLeast();
            // ...
        } catch (Exception e) {
            // ...
        }
    }
    
    // 默认轮询选择队列
    return tpInfo.selectOneMessageQueue(lastBrokerName);
}</code></pre>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">特点：</h4>
                    <ul class="space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>动态感知Broker的可用性和响应时间</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>自动规避最近发送失败或响应慢的Broker</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>提高消息发送的成功率和性能</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-blue-500 mt-1 mr-2"></i>
                            <span>适用于对可靠性要求高的场景</span>
                        </li>
                    </ul>
                </div>
                <div class="diagram-container">
                    <div class="mermaid">
                        graph TD
                            A[Producer] --> B{延迟容错检查}
                            B -->|Broker1响应慢| C[选择Broker2]
                            B -->|Broker2正常| D[选择Broker2]
                            B -->|Broker3故障| E[跳过Broker3]
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">1.3 自定义队列选择器</h3>
            <p class="mb-6">RocketMQ允许用户实现自定义的队列选择器（MessageQueueSelector），以满足特定的业务需求：</p>
            
            <div class="code-block p-6 rounded-xl mb-8">
                <pre><code class="language-java">public interface MessageQueueSelector {
    MessageQueue select(final List<MessageQueue> mqs, final Message msg, final Object arg);
}</code></pre>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-blue-600">Hash选择器</h4>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public MessageQueue select(List<MessageQueue> mqs, 
                          Message msg, Object arg) {
    String key = (String) arg;
    int index = key.hashCode() % mqs.size();
    return mqs.get(Math.abs(index));
}</code></pre>
                    </div>
                    <p class="text-sm text-gray-600">根据消息的某个属性（如订单ID）进行哈希，确保相同属性的消息发送到同一个队列，用于顺序消息场景。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-blue-600">随机选择器</h4>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public MessageQueue select(List<MessageQueue> mqs, 
                          Message msg, Object arg) {
    int index = random.nextInt(mqs.size());
    return mqs.get(index);
}</code></pre>
                    </div>
                    <p class="text-sm text-gray-600">随机选择一个队列，适用于对消息顺序没有要求的场景。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-blue-600">最小负载选择器</h4>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public MessageQueue select(List<MessageQueue> mqs, 
                          Message msg, Object arg) {
    // 根据监控数据选择负载最小的队列
    return findLeastLoadedQueue(mqs);
}</code></pre>
                    </div>
                    <p class="text-sm text-gray-600">选择当前负载最小的队列，需要额外的负载监控机制。</p>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">2. 故障转移机制</h3>
            <p class="mb-6">RocketMQ Producer具有自动故障转移能力，当发送消息到某个Broker失败时，会自动尝试其他Broker：</p>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="bg-blue-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-blue-700 flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i> 重试机制
                    </h4>
                    <ul class="space-y-2">
                        <li>默认重试2次（共3次发送尝试）</li>
                        <li>可通过<code class="bg-blue-100 px-1 rounded">setRetryTimesWhenSendFailed</code>方法设置重试次数</li>
                    </ul>
                </div>
                
                <div class="bg-blue-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-blue-700 flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i> 故障规避
                    </h4>
                    <ul class="space-y-2">
                        <li>记录发送失败的Broker</li>
                        <li>在一定时间内避免向该Broker发送消息</li>
                        <li>时间窗口会随着失败次数增加而延长</li>
                    </ul>
                </div>
                
                <div class="bg-blue-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-blue-700 flex items-center">
                        <i class="fas fa-heartbeat mr-2"></i> 自动恢复
                    </h4>
                    <ul class="space-y-2">
                        <li>定期检测故障Broker的状态</li>
                        <li>当Broker恢复后，自动将其加入可用Broker列表</li>
                    </ul>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">3. 负载均衡优化策略</h3>
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">合理设置队列数量</h4>
                    <ul class="space-y-2 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>队列数量应大于等于Consumer数量</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>建议设置为Consumer数量的1-2倍</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>过多的队列会增加系统开销</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">启用延迟容错机制</h4>
                    <ul class="space-y-2 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>设置<code class="bg-gray-100 px-1 rounded">producer.setSendLatencyFaultEnable(true)</code></span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>配置合适的容错参数</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">合理分布Topic</h4>
                    <ul class="space-y-2 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>将不同Topic分布在不同的Broker上</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>避免热点Broker</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Consumer Section -->
        <section id="consumer" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-users text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold">Consumer端的负载均衡策略</h2>
            </div>
            <p class="text-lg text-gray-700 mb-8">RocketMQ Consumer端的负载均衡是指将一个Topic的多个队列均衡地分配给同一消费组（Consumer Group）下的多个消费者实例，确保每个队列只被一个消费者消费，同时尽量平均分配队列数量。</p>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 text-purple-600 flex items-center">
                        <i class="fas fa-project-diagram mr-2"></i> 负载均衡基本原理
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-users text-purple-500 mt-1 mr-2"></i>
                            <span><strong>消费者组（Consumer Group）：</strong>同一组内的消费者共同消费一个Topic的消息</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-list-ol text-purple-500 mt-1 mr-2"></i>
                            <span><strong>队列（Queue）：</strong>每个Topic包含多个队列，是负载均衡的基本单位</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-random text-purple-500 mt-1 mr-2"></i>
                            <span><strong>重平衡（Rebalance）：</strong>当消费者数量变化时，重新分配队列的过程</span>
                        </li>
                    </ul>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            subgraph Consumer Group
                                C1[Consumer 1] --> Q1[Queue 1]
                                C1 --> Q2[Queue 2]
                                C2[Consumer 2] --> Q3[Queue 3]
                                C2 --> Q4[Queue 4]
                            end
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">2. 队列分配策略</h3>
            <p class="mb-6">RocketMQ提供了多种队列分配策略，可以通过<code class="bg-gray-100 px-1 rounded">AllocateMessageQueueStrategy</code>接口的不同实现来选择：</p>
            
            <div class="code-block p-6 rounded-xl mb-8">
                <pre><code class="language-java">public interface AllocateMessageQueueStrategy {
    /**
     * 分配队列
     * @param consumerGroup 消费者组名
     * @param currentCID 当前消费者ID
     * @param mqAll 当前Topic的所有队列
     * @param cidAll 当前消费者组内的所有消费者ID
     * @return 分配给当前消费者的队列列表
     */
    List<MessageQueue> allocate(String consumerGroup, String currentCID, 
                               List<MessageQueue> mqAll, List<String> cidAll);
}</code></pre>
            </div>

            <h4 class="text-xl font-semibold mb-4 text-gray-700">RocketMQ内置的分配策略：</h4>
            
            <div class="grid md:grid-cols-2 gap-6 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h5 class="text-lg font-semibold mb-3 text-purple-600">平均分配策略（默认）</h5>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public List<MessageQueue> allocate(String consumerGroup, String currentCID, 
                                 List<MessageQueue> mqAll, List<String> cidAll) {
    // 计算平均每个消费者分配的队列数
    int averageSize = mqAll.size() / cidAll.size();
    // 计算余数
    int remainder = mqAll.size() % cidAll.size();
    // 当前消费者在所有消费者中的索引
    int index = cidAll.indexOf(currentCID);
    // 计算起始索引和队列数
    int startIndex = averageSize * index;
    int size = averageSize;
    // 处理余数，前remainder个消费者多分配一个队列
    if (index < remainder) {
        startIndex += index;
        size++;
    } else {
        startIndex += remainder;
    }
    // 分配队列
    List<MessageQueue> result = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        result.add(mqAll.get((startIndex + i) % mqAll.size()));
    }
    return result;
}</code></pre>
                    </div>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>尽量平均分配队列，每个消费者分配的队列数量相差不超过1</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>简单高效，适用于大多数场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>不考虑队列负载情况</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h5 class="text-lg font-semibold mb-3 text-purple-600">环形分配策略</h5>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public List<MessageQueue> allocate(String consumerGroup, String currentCID, 
                                 List<MessageQueue> mqAll, List<String> cidAll) {
    List<MessageQueue> result = new ArrayList<MessageQueue>();
    int index = cidAll.indexOf(currentCID);
    // 轮流分配队列
    for (int i = index; i < mqAll.size(); i += cidAll.size()) {
        result.add(mqAll.get(i % mqAll.size()));
    }
    return result;
}</code></pre>
                    </div>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>按照消费者顺序轮流分配队列</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>分配结果较为均匀</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>当消费者数量变化时，重分配的影响较大</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h5 class="text-lg font-semibold mb-3 text-purple-600">一致性哈希分配策略</h5>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public List<MessageQueue> allocate(String consumerGroup, String currentCID, 
                                 List<MessageQueue> mqAll, List<String> cidAll) {
    // 构建一致性哈希环
    for (String cid : cidAll) {
        consistentHashRouter.addNode(cid, virtualNodeCnt);
    }
    // 分配队列
    List<MessageQueue> result = new ArrayList<MessageQueue>();
    for (MessageQueue mq : mqAll) {
        String owner = consistentHashRouter.routeNode(mq.getBrokerName() + mq.getQueueId());
        if (currentCID.equals(owner)) {
            result.add(mq);
        }
    }
    return result;
}</code></pre>
                    </div>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>使用一致性哈希算法，减少重平衡时的队列迁移</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>当消费者数量变化时，只有部分队列需要重新分配</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>适用于消费者经常变化的场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>分配可能不够均匀</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h5 class="text-lg font-semibold mb-3 text-purple-600">机房感知分配策略</h5>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-java">public List<MessageQueue> allocate(String consumerGroup, String currentCID, 
                                 List<MessageQueue> mqAll, List<String> cidAll) {
    // 获取当前消费者所在机房
    String currentIDC = IDCUtil.getIDC(currentCID);
    // 筛选同机房的队列
    List<MessageQueue> localQueues = new ArrayList<MessageQueue>();
    for (MessageQueue mq : mqAll) {
        if (currentIDC.equals(IDCUtil.getBrokerIDC(mq.getBrokerName()))) {
            localQueues.add(mq);
        }
    }
    // 筛选同机房的消费者
    List<String> localConsumers = new ArrayList<String>();
    for (String cid : cidAll) {
        if (currentIDC.equals(IDCUtil.getIDC(cid))) {
            localConsumers.add(cid);
        }
    }
    // 使用平均分配策略在同机房内分配队列
    AllocateMessageQueueAveragely averagelyAllocate = new AllocateMessageQueueAveragely();
    return averagelyAllocate.allocate(consumerGroup, currentCID, localQueues, localConsumers);
}</code></pre>
                    </div>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>支持跨机房部署场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>优先消费同机房的队列，减少跨机房访问</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>提高消费效率，降低网络延迟</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-plus-circle text-purple-500 mt-1 mr-2"></i>
                            <span>适用于多机房部署的大型系统</span>
                        </li>
                    </ul>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">3. 重平衡触发机制</h3>
            <p class="mb-6">RocketMQ在以下情况下会触发重平衡（Rebalance）：</p>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="bg-purple-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-purple-700 flex items-center">
                        <i class="fas fa-user-plus mr-2"></i> 消费者变化
                    </h4>
                    <ul class="space-y-2">
                        <li>新消费者加入消费者组</li>
                        <li>现有消费者宕机或主动下线</li>
                    </ul>
                </div>
                
                <div class="bg-purple-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-purple-700 flex items-center">
                        <i class="fas fa-list-ol mr-2"></i> 队列数量变化
                    </h4>
                    <ul class="space-y-2">
                        <li>增加或减少Topic的队列数量</li>
                        <li>新增或删除Broker节点</li>
                    </ul>
                </div>
                
                <div class="bg-purple-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-purple-700 flex items-center">
                        <i class="fas fa-clock mr-2"></i> 定时检查
                    </h4>
                    <ul class="space-y-2">
                        <li>消费者定期（默认20秒）检查队列分配情况</li>
                        <li>发现变化时触发重平衡</li>
                    </ul>
                </div>
            </div>

            <h4 class="text-xl font-semibold mb-4 text-gray-700">重平衡流程：</h4>
            <div class="diagram-container mb-12">
                <div class="mermaid">
                    graph TD
                        A[消费者] --> B[从NameServer获取队列信息]
                        B --> C[从Broker获取消费者列表]
                        C --> D[根据策略计算分配的队列]
                        D --> E[停止消费不再分配的队列]
                        E --> F[开始消费新分配的队列]
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">4. 负载均衡优化策略</h3>
            <div class="grid md:grid-cols-4 gap-6 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">合理设置消费者数量</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>消费者数量不应超过队列数量</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>建议设置为队列数量的50%-80%</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">选择合适的分配策略</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>消费者稳定场景：使用平均分配策略</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>消费者频繁变化场景：使用一致性哈希策略</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">调整重平衡参数</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>设置合理的重平衡间隔时间</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>避免频繁触发重平衡</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">提高消费并行度</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>增加消费线程数</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-purple-500 mt-1 mr-2"></i>
                            <span>批量消费消息</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Broker Section -->
        <section id="broker" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-server text-3xl text-orange-600 mr-4"></i>
                <h2 class="text-3xl font-bold">Broker集群的负载均衡实现</h2>
            </div>
            <p class="text-lg text-gray-700 mb-8">Broker集群的负载均衡是指在多个Broker节点之间均衡分配消息存储和处理负载，确保系统资源得到充分利用，避免单点过载。</p>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">1. 多Master架构</h3>
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <p class="mb-4">RocketMQ支持多Master部署架构，每个Master负责不同的Topic分片：</p>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-orange-500 mt-1 mr-2"></i>
                            <span>每个Master独立工作，互不影响</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-orange-500 mt-1 mr-2"></i>
                            <span>Topic的队列分布在多个Master上</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-orange-500 mt-1 mr-2"></i>
                            <span>单个Master故障只影响部分Topic</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-orange-500 mt-1 mr-2"></i>
                            <span>水平扩展能力强</span>
                        </li>
                    </ul>
                </div>
                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            subgraph Broker集群
                                B1[Master1] -->|TopicA队列1-4| P[Producer]
                                B2[Master2] -->|TopicA队列5-8| P
                                B3[Master3] -->|TopicB队列1-4| P
                                B4[Master4] -->|TopicB队列5-8| P
                            end
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">2. Topic队列分布机制</h3>
            <p class="mb-6">RocketMQ通过合理分布Topic的队列，实现Broker集群的负载均衡：</p>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">自动创建Topic</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-magic text-orange-500 mt-1 mr-2"></i>
                            <span>当Producer发送消息到不存在的Topic时，会自动创建Topic</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-magic text-orange-500 mt-1 mr-2"></i>
                            <span>默认在每个Broker上创建4个读队列和4个写队列</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">手动创建Topic</h4>
                    <div class="code-block p-4 rounded-lg mb-3">
                        <pre><code class="language-bash">sh mqadmin updateTopic -n 192.168.1.100:9876 \
  -b 192.168.1.101:10911 -t TestTopic -r 8 -w 8</code></pre>
                    </div>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-wrench text-orange-500 mt-1 mr-2"></i>
                            <span>通过管理工具创建Topic时，可以指定队列分布</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-wrench text-orange-500 mt-1 mr-2"></i>
                            <span>可以根据Broker负载情况，调整队列分布</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">动态调整队列</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-sync-alt text-orange-500 mt-1 mr-2"></i>
                            <span>可以在运行时增加或减少队列数量</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-sync-alt text-orange-500 mt-1 mr-2"></i>
                            <span>调整队列分布，平衡Broker负载</span>
                        </li>
                    </ul>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">3. 读写分离机制</h3>
            <p class="mb-6">RocketMQ支持读写分离，可以将读请求分散到从节点，减轻主节点负担：</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">Slave读取功能</h4>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                            <span>配置<code class="bg-orange-100 px-1 rounded">slaveReadEnable=true</code>启用从节点读取</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                            <span>消费者可以从Slave节点读取消息</span>
                        </li>
                    </ul>
                    
                    <h4 class="text-lg font-semibold mt-6 mb-3 text-orange-600">读负载均衡</h4>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                            <span>Producer只向Master写入消息</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                            <span>Consumer可以从Master或Slave读取消息</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                            <span>通过配置<code class="bg-orange-100 px-1 rounded">brokerPermission</code>控制读写权限</span>
                        </li>
                    </ul>
                </div>
                <div class="diagram-container">
                    <div class="mermaid">
                        graph TD
                            P[Producer] -->|Write| M[Master]
                            M -->|Sync| S1[Slave1]
                            M -->|Sync| S2[Slave2]
                            C1[Consumer1] -->|Read| M
                            C2[Consumer2] -->|Read| S1
                            C3[Consumer3] -->|Read| S2
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">4. 流量控制机制</h3>
            <p class="mb-6">RocketMQ提供多种流量控制机制，避免Broker过载：</p>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="bg-orange-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-orange-700">生产端流控</h4>
                    <ul class="space-y-2">
                        <li>限制单个Producer的发送速率</li>
                        <li>限制单个Broker的接收速率</li>
                    </ul>
                </div>
                
                <div class="bg-orange-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-orange-700">消费端流控</h4>
                    <ul class="space-y-2">
                        <li>限制单个Consumer的消费速率</li>
                        <li>限制单个Broker的发送速率</li>
                    </ul>
                </div>
                
                <div class="bg-orange-50 p-6 rounded-xl">
                    <h4 class="text-lg font-semibold mb-3 text-orange-700">资源隔离</h4>
                    <ul class="space-y-2">
                        <li>不同Topic使用不同的线程池</li>
                        <li>优先级队列机制</li>
                    </ul>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">5. 动态扩容机制</h3>
            <p class="mb-6">RocketMQ支持动态扩容，可以在不停机的情况下增加Broker节点：</p>
            
            <div class="diagram-container mb-8">
                <div class="mermaid">
                    graph LR
                        A[部署新Broker] --> B[向NameServer注册]
                        B --> C[创建新Topic队列]
                        C --> D[逐步迁移流量]
                        D --> E[负载重平衡]
                </div>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">新增Broker</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-server text-orange-500 mt-1 mr-2"></i>
                            <span>部署新的Broker节点</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-server text-orange-500 mt-1 mr-2"></i>
                            <span>向NameServer注册</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">Topic迁移</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-exchange-alt text-orange-500 mt-1 mr-2"></i>
                            <span>创建新的Topic队列在新Broker上</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-exchange-alt text-orange-500 mt-1 mr-2"></i>
                            <span>逐步将流量迁移到新队列</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">负载重平衡</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-balance-scale text-orange-500 mt-1 mr-2"></i>
                            <span>调整Topic队列分布</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-balance-scale text-orange-500 mt-1 mr-2"></i>
                            <span>平衡各Broker负载</span>
                        </li>
                    </ul>
                </div>
            </div>

            <h3 class="text-2xl font-semibold mb-6 text-gray-800">6. 监控与告警</h3>
            <p class="mb-6">RocketMQ提供完善的监控指标，帮助及时发现负载不均衡问题：</p>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">关键监控指标</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-chart-line text-orange-500 mt-1 mr-2"></i>
                            <span>消息生产TPS</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chart-line text-orange-500 mt-1 mr-2"></i>
                            <span>消息消费TPS</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chart-line text-orange-500 mt-1 mr-2"></i>
                            <span>磁盘使用率</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chart-line text-orange-500 mt-1 mr-2"></i>
                            <span>内存使用率</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chart-line text-orange-500 mt-1 mr-2"></i>
                            <span>网络流量</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">告警机制</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-bell text-orange-500 mt-1 mr-2"></i>
                            <span>设置负载阈值告警</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-bell text-orange-500 mt-1 mr-2"></i>
                            <span>及时发现过载Broker</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <h4 class="text-lg font-semibold mb-3 text-orange-600">可视化监控</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-tv text-orange-500 mt-1 mr-2"></i>
                            <span>RocketMQ Dashboard</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-tv text-orange-500 mt-1 mr-2"></i>
                            <span>第三方监控系统集成</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Best Practices Section -->
        <section id="best-practices" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-star text-3xl text-yellow-500 mr-4"></i>
                <h2 class="text-3xl font-bold">最佳实践</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <!-- Producer Best Practices -->
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 text-blue-600 flex items-center">
                        <i class="fas fa-paper-plane mr-2"></i> Producer端最佳实践
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">启用延迟容错机制</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">producer.setSendLatencyFaultEnable(true);</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">合理设置重试次数</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">producer.setRetryTimesWhenSendFailed(3);</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">使用异步发送提高吞吐量</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">producer.send(msg, new SendCallback() {
    @Override
    public void onSuccess(SendResult sendResult) {
        // 处理成功逻辑
    }
    
    @Override
    public void onException(Throwable e) {
        // 处理异常逻辑
    }
});</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Consumer Best Practices -->
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 text-purple-600 flex items-center">
                        <i class="fas fa-users mr-2"></i> Consumer端最佳实践
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">选择合适的分配策略</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">consumer.setAllocateMessageQueueStrategy(
    new AllocateMessageQueueConsistentHash()
);</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">调整消费线程数</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">consumer.setConsumeThreadMin(20);
consumer.setConsumeThreadMax(64);</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">批量消费提高效率</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-java">consumer.setConsumeMessageBatchMaxSize(32);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Broker Best Practices -->
                <div class="card bg-white p-6 rounded-xl shadow-md transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 text-orange-600 flex items-center">
                        <i class="fas fa-server mr-2"></i> Broker端最佳实践
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">合理规划Topic分布</h4>
                            <ul class="text-sm text-gray-600 space-y-1">
                                <li>重要Topic分布在多个Broker上</li>
                                <li>根据Topic流量特征调整队列数量</li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">启用读写分离</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-properties">slaveReadEnable=true</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">设置流量控制阈值</h4>
                            <div class="code-block p-3 rounded-lg">
                                <pre><code class="language-properties"># 生产端流控，单位：字节
transientStorePoolSize=5
# 消费端流控
brokerFastFailureEnable=true</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">定期检查负载均衡状态</h4>
                            <ul class="text-sm text-gray-600 space-y-1">
                                <li>监控各Broker负载</li>
                                <li>及时调整不均衡的Topic分布</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-semibold">技术小馆</h3>
                    <p class="text-gray-400">专注于分布式系统与中间件技术</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors">
                        <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            },
            securityLevel: 'loose'
        });

        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });

        // Highlight active nav item on scroll
        const sections = document.querySelectorAll('section');
        const navItems = document.querySelectorAll('.nav-item');
        
        window.addEventListener('scroll', () => {
            let current = '';
            
            sections.forEach(section => {
                const sectionTop = section.offsetTop;
                const sectionHeight = section.clientHeight;
                
                if (pageYOffset >= sectionTop - 100) {
                    current = section.getAttribute('id');
                }
            });
            
            navItems.forEach(item => {
                item.classList.remove('border-blue-500', 'text-gray-700');
                if (item.getAttribute('href') === `#${current}`) {
                    item.classList.add('border-blue-500', 'text-gray-700');
                }
            });
        });
    </script>
</body>
</html>
```